package ui

import (
	"fmt"
	"go-demo/designpattern/factory/abstractfactory/ui/mac"
	"go-demo/designpattern/factory/abstractfactory/ui/win"
	. "go-demo/designpattern/factory/abstractfactory/ui/factory"
)

func GetUIFactory(name string) UIFactory {
	switch name {
	case "mac":
		return &mac.MacFactory{}
	case "win":
		return &win.WinFactory{}
	}
	return nil
}

// BuildLoginForm 构建登录表单
func BuildLoginForm(factory UIFactory) {
	// 创建组件
	button := factory.CreateButton()
	textField := factory.CreateTextField()

	// 渲染
	fmt.Println(button.Render())
	fmt.Println(textField.Render())

	// 模拟交互
	button.OnClick()
	textField.Input("admin")
}
